package com.service.weChatWifiLogin.controller;

import com.service.config.utils.Result;
import com.service.weChatWifiLogin.dto.ConnectErrorInfoDto;
import com.service.weChatWifiLogin.dto.CustomerRegisterDto;
import com.service.weChatWifiLogin.dto.SsIdName;
import com.service.weChatWifiLogin.service.ShopCustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;


/**
 * 店铺顾客表(ShopCustomer)表控制层
 *
 * @author makejava
 * @since 2021-06-16 17:11:02
 */
@RestController
@RequestMapping("shopCustomer")
@Api(value = "店铺顾客",tags = "店铺顾客")
public class ShopCustomerController {
    /**
     * 服务对象
     */
    @Resource
    private ShopCustomerService shopCustomerService;



    @PostMapping("queryShopLists")
    @ApiOperation(value = "查询ssid对应的店铺列表")
    @ResponseBody
    public Result queryShopLists(@RequestBody List<SsIdName> ssidDtos) {
        try {
            return Result.ok().setData(shopCustomerService.queryShopsBySsids(ssidDtos));

        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }

    }


    @PostMapping("queryAuthorized")
    @ApiOperation(value = "获取客户信息并保存")
    @ResponseBody
    public Result queryAuthorized(@RequestBody CustomerRegisterDto customerRegisterDto,
                                  @RequestHeader(value = "token",required = false) @ApiParam("token令牌") String bAuthToken) throws Exception {
        try {
            return shopCustomerService.queryAuthorized(customerRegisterDto,bAuthToken);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }
    }
    @PostMapping("addConnectErrorInfo")
    @ApiOperation(value = "保存连接失败信息")
    @ResponseBody
    public Result addConnectErrorInfo(@RequestBody ConnectErrorInfoDto connectErrorInfoDto,
                                      @RequestHeader(value = "token",required = false) @ApiParam("token令牌") String bAuthToken) throws Exception {
        try {
            return shopCustomerService.addConnectErrorInfo(connectErrorInfoDto,bAuthToken);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }
    }
    @GetMapping("queryPhone")
    @ApiOperation(value = "查询手机号是否授权")
    @ResponseBody
    public Result queryPhone(@RequestParam("code") String code,
                             @RequestHeader(value = "token",required = false) @ApiParam("token令牌") String bAuthToken) throws Exception {
        try {
            return shopCustomerService.queryPhone(code,bAuthToken);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }

    }



}
